package org.deyang.tools.amazon.pricetracker;

import java.util.ArrayList;
import java.util.List;

import org.deyang.tools.amazon.pojos.DealDetail;
import org.deyang.tools.amazon.pojos.PriceChangeEntity;

public abstract class PriceAnalyzer {

	protected DealDetail dd = new DealDetail();

	public abstract boolean isDeal(int daysPeriod);

	public PriceAnalyzer() {
		super();
	}

	protected List<PriceChangeEntity> generateProcessList(String priceString) {
		List<PriceChangeEntity> result = null;
		if (priceString != null){
			result =  new ArrayList<PriceChangeEntity>();
			String[] prices = priceString.split(",");
			
			for (int i = 0; i < prices.length; i = i + 2){
				//For latest price record, even it is -1 ,we will keep it
				if (i < prices.length - 1 && !prices[i + 1].equals("-1")){
					try {
						PriceChangeEntity changeEntity = new PriceChangeEntity();
						changeEntity.setHours(Integer.parseInt(prices[i]));
						changeEntity.setPriceValue(Integer.parseInt(prices[i + 1]));
						result.add(changeEntity);
					} catch (NumberFormatException e) {
						continue;
					}
				}
			}
	
		}
		return result;				
		
	}

	public DealDetail getDealDetail() {
		return this.dd;
		
	}

}